package Thread.New.Semaphore;

import java.util.concurrent.Semaphore;

/**
 * @author 君未洋
 */
public class RunnableImpl implements Runnable {
    private Semaphore semaphore ;
    private String name;

    public RunnableImpl(Semaphore semaphore,String name) {
        this.semaphore = semaphore;
        this.name = name;
    }

    @Override
    public void run() {
        try {
            semaphore.acquire();
            System.out.println("我拿到位置了"+name);
            Thread.sleep(1000);
            System.out.println("我施放资源了"+name);

        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        finally {
            semaphore.release();

        }

    }
}
